Redux Observable Ajax Default Header Hack
Ever wanted to use ajax.get()
, ajax.post()
, ajax.put()
and the rest without having to set the authorization header every time? Welcome to the future!
This is an annoying problem since the parameters for get
, getJSON
, and delete
are not the same as patch
, post
, and put
.
In the example below a Proxy is used to take the ajax method and then grab the position of the header
object. The object then has a the token added to it, and is then called with the modified arguments.
This is working with TS 4.5.4, however I did sneak an any
in... would love to get rid of that if anyone has any suggestions.
You can use [[Custom Operators]] to wrap this new authenticated ajax function to use easily in existing Epics.